<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        input {
            height: 40px;
            width: 400px;
            padding-left: 20px;
            font-size: 20px;
        }
    </style>
</head>
<body>

    <input type="text" placeholder="请输入url地址">
    <p>环境: <span></span> </p>


    <script src="./debounce.js"></script>
    <script>
        // 要求:
            // 判断路径是否为超文本传输协议(http服务环境)

        // 1. 获取页面相关的标签
        var inp = document.querySelector("input[type='text']")
        var txt = document.querySelector("p span")

        // 2. 编写正则表达式
        var regExp = /^(https?):[//]/;

        // 3. 事件绑定
        inp.oninput = inp.onclick = debounce(function(){
            // 获取输入的值
            var _url = this.value;
            // 校验路径
            regExp.test(_url) == true ? txt.innerText = "http环境":txt.innerText = "其他环境";
        },300)


        // 拆分绑定事件
        // inp.oninput = function(){}
        // inp.onclick = function(){}

        // file:///D:/workspace/javascript
        // http://127.0.0.1:5500/

    </script>
</body>
</html>